"use strict";
let someValue = "this is a string";
let strLength1 = someValue.length;
// 如果要写断言，建议用as，因为上面的形式在react中会有歧义。尖括号语法与JSX的标签语法相冲突
let strLength2 = someValue.length;
function getLength(type) {
    console.log(type.length);
}
getLength("hello world");
function print(person) {
    console.log(person.name);
    console.log(person.score);
}
class Animal {
    eat() {
        console.log('animal eat');
    }
}
class Dog extends Animal {
    eat() {
        console.log('dog eat');
    }
    bark() {
        console.log('dog bark');
    }
}
class Cat extends Animal {
    eat() {
        console.log('cat eat');
    }
    meow() {
        console.log('cat meow');
    }
}
function feed(animal) {
    animal.meow();
}
function feedAnimal(animal) {
    if (animal instanceof Dog) {
        animal.bark();
    }
    else if (animal instanceof Cat) {
        animal.meow();
    }
    else {
        animal.eat();
    }
}
/* const inputDom = document.querySelector("input") as HTMLInputElement;
inputDom.addEventListener("change", e => {
  console.log((e.target as HTMLInputElement).value)
}) */
const obj = {
    name: "jack",
    age: 18
};
obj.sex = "男";
console.log(obj.sex);
// (window as any).foo = 1;
/* export { }
declare global {
  interface Window {
    foo: number
  }
}
window.foo = 1; */
// 第三方API或者历史遗留问题，any或者unknown类型的存在
function getData(id) {
    return {
        id: 1,
        name: "jack",
        age: 18
    };
}
const user = getData(1);
console.log(user.name);
let str = "123";
// let n = str as number; // error
let str1 = "hello";
let str2 = "hello";
str2 = str1;
// str2 = str1 as string;
str1 = str2;
let a = new Animal();
let b = new Dog();
// a = b;
b = a;
b.eat();
// b.bark(); // 是非常不安全的，因为b的类型是Animal，但是bark方法是Dog的方法
let maybeString = "hello";
let definitelyString = maybeString;
function getRandom(length) {
    if (!length) {
        return undefined;
    }
    return Math.random().toString(36).slice(-length);
}
let s = getRandom(6);
// 可以使用类型断言
s.charAt(0);
// 由于就是字符串和非空的处理，可以使用非空断言
s.charAt(0);
function getBox() {
    if (Math.random() > 0.5) {
        return {
            id: 1,
            name: "box1",
        };
    }
    return undefined;
}
function createProduction(box) {
    // todos...
}
createProduction(getBox());
// 非空断言
createProduction(getBox());
let str3 = "123Hello";
let n = str3;
console.log(n);
